<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

$course_id = mysql_real_escape_string(strip_tags($_GET['id']));
$subject_id = mysql_real_escape_string(strip_tags($_GET['sid']));

$get_subject_data = mysql_query("SELECT * FROM course_subjects WHERE id = $subject_id");
$subject_name = mysql_result($get_subject_data,0,'subject_title');
$abbreviation = mysql_result($get_subject_data,0,'abbreviation');


$get_course_data = mysql_query("SELECT * FROM courses WHERE id='$course_id'");
$course_number=mysql_result($get_course_data,0,"course_number");
$course_name=mysql_result($get_course_data,0,"title");
$hours_per_week=mysql_result($get_course_data,0,"hours_per_week");
$graduate=mysql_result($get_course_data,0,"graduate_level");
$orig_lab_id=mysql_result($get_course_data,0,"lab_number");

echo "<p>";
	echo "<a href='courses.php?id=$subject_id'>&lt;&lt; Back to Courses Portal</a>";
echo "</p>";
echo "<h1>Edit Course for $subject_name</h1>";

$query="SELECT * FROM courses WHERE course_subject_id=$subject_id";
$result=mysql_query($query);

$num_rows=mysql_numrows($result);

$i=0;

echo "<form action='edit_do.php' method='post'>";

//start table
echo "<table border='0'>";
	
	//create table row
	echo "<tr>";
		echo "<td width=180><b>Course Number: </b></td>";
		echo "<td>$abbreviation <input type='text' name='course_num' value='$course_number'></td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Course Name: </b></td>";
		echo "<td><input type='text' name='course_name' value='$course_name'></td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Credits: </b></td>";
		echo "<td><input type='text' name='credits' value='$hours_per_week'></td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Graduate Course: </b></td>";
		echo '<td>';
			echo "<select name='grad'>";
				if ($graduate)
				{
					echo "<option value=1 selected='selected'>Yes</option>";
					echo "<option value=0>No</option>";
				}
				else
				{
					echo "<option value=1>Yes</option>";
					echo "<option value=0 selected='selected'>No</option>";
				}
			echo "</select>";
		echo '</td>';
	echo "</tr>";
	
	echo "<tr>";
		echo "<td><b>Lab:</b></td>";
		echo "<td>";
			echo "<select name='lab'>";
				echo "<option value=0>NONE</option>";
				while ($i < $num_rows)
				{
					$lab_id=mysql_result($result,$i,"id");
					$lab_number=mysql_result($result,$i,"course_number");
					if ($orig_lab_id == $lab_id)
					{
						echo "<option value=$lab_id selected='selected'>$abbreviation $lab_number</option>";
					}
					else
					{
						echo "<option value=$lab_id>$abbreviation $lab_number</option>";
					}
					$i++;
				}
			echo "</select>";
		echo '</td>';
	echo "</tr>";


//end table tag
echo "</table>";



echo "<input type='hidden' name='id' value='$course_id'>";
echo "<input type='hidden' name='sid' value='$subject_id'>";
echo "<p><input type='submit'></p>";
echo '</form>';



?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>